// 格式化金额(格式化总价时展示用)
export function formatDistance(distanceStr) {
	if (!validateToNumber(distanceStr)) {
		return "";
	}
	let num = parseFloat(distanceStr);
	if (num === 0) {
		return 0;
	}
	if (!num) {
		return "";
	}
	if (num < 1000) {
		return num + 'm'
	}

	return (num / 1000).toFixed(2) + 'km';
}

export function formatGuaranteeDate(varStr) {
	if (!varStr || parseFloat(varStr) == 0) {
		return ''
	}
	let year = '';
	let mouth = '';
	let day = '';
	let hh = '';
	let mm = '';
	let ss = '';
	if (varStr.length === 14) {
		year = varStr.slice(0, 4)
		mouth = varStr.slice(4, 6)
		day = varStr.slice(6, 8)
		hh = varStr.slice(8, 10)
		mm = varStr.slice(10, 12)
		ss = varStr.slice(12, 14)
	}
	return [year, mouth, day].join('-') + ' ' + [hh, mm, ss].join(':');
}

// 验证是否是数字或字符串
function validateToNumber(val) {
	return typeof val === "string" || typeof val === "number";
}
